#ifndef SHELLINVOKER_H
#define SHELLINVOKER_H

#include <QProcess>

class ShellInvoker : public QObject
{
    Q_OBJECT

    //Q_PROPERTY(QString response READ response NOTIFY responseChanged)
    Q_PROPERTY(QString outputLine READ outputLine)// NOTIFY outputLineChanged)
    Q_PROPERTY(int processState READ processState)
    Q_PROPERTY(QString waitFor WRITE setWaitFor)
    Q_PROPERTY(QString writeLine WRITE write)
    Q_PROPERTY(QString wDir WRITE setWorkingDir)

public:
    Q_INVOKABLE void shellAction(QString str,QStringList sArg);
    Q_INVOKABLE void shellWholeAction(QString command);
    Q_INVOKABLE void kill();
    QString outputLine() const;
    int processState() const;
    void setWaitFor(QString waitFor);
    void setWorkingDir(QString wDir);
    Q_INVOKABLE void write(QString line);
    ShellInvoker();
    ~ShellInvoker();

signals:
    void outputLineChanged();
    void launched();
    void finished(int status);

private:
     void startProcess();

     QString m_outputLine;
     QProcess *innerProcess;
     QString m_waitFor;
     QString m_cmd;
     QStringList m_sArg;
     bool m_reRunning;

private slots:
    void readyToRead();
    void readyToReadError();
    void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
};




#endif // SHELLINVOKER_H

